package ecitys.gcs

import ecitys.types.Money;

class CalculoVerbaBase {
	Funcionario funcionario
	Verba verba
	
	@Override
	static Money doCalculo(){
		return Money.newMoneyFromReal(getValorFromVerbaBase());
	}
	
	Money getValorFromVerbaBase(){
		def verbas = ComposicaoVerbaBase.findAllByVerbaBase(verba.verbaBase)
		def Money result = Money.newMoneyFromReal(0);
		for (verba in verbas) {
			//implementar fabrica para criacao do tipo de calculo
			
			result += verba.calculo.doCalculo()
		}
		
		return result
	}
	
	

    public CalculoVerbaBase(Funcionario funcionario, Verba verba) {
		super();
		this.funcionario = funcionario;
		this.verba = verba;
	}

	static mapping = {
		table schema:"gcs"
	}

    
	static transients = ['valorFromVerbaBase']
	
	static constraints = {
    }
}
